<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>

        console.log(filterWords('wc 正则真tm简单 TmD Wc'));

        function filterWords(str) {
            // 敏感词   tmd   tm  wc  ...
            var arr = ['tmd', 'wc', 'tm'];
            var a = arr.join('|');
            console.log(a);
            // var reg = /a/ig;  // 错的
            var reg = new RegExp(a, 'ig');

            return str.replace(reg, '**')

        }

    </script>

</body>

</html>